<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------


namespace app\common\service\douyin;
/**
 * 抖音头条登录
 * Class DouyinLoginService
 * @package app\common\server
 */
class DouyinLoginService
{


    protected static $appid;
    protected static $secret;

    protected static  $url;

//    public function __construct()
//    {
//        $config = [
//            'appid' => config('douyin.site.app_id'),
//            'secret' => config('douyin.site.app_secret'),
//        ];
//        self::$appid = $config['appid'] ?? null;
//        self::$secret = $config['secret'] ?? null;
//        self::$url = "https://developer.toutiao.com/api/apps/v2/jscode2session";
//    }

    public static function ttlogin($code, $anonymous_code = null)
    {

        $config = [
            'appid' => config('douyin.site.app_id'),
            'secret' => config('douyin.site.app_secret'),
        ];
        self::$appid = $config['appid'] ?? null;
        self::$secret = $config['secret'] ?? null;
        $url = "https://developer.toutiao.com/api/apps/v2/jscode2session";
        $params = [
            'code' => $code,
            'appid' => self::$appid,
            'secret' => self::$secret,
        ];
        // 其他逻辑处理
        $res = curlPost($url,$params);
        if ($res){
            $res = json_decode($res,true);
            if ($res['err_no'] == 0&&isset($res['data']['openid'])){
                $data['openid'] = $res['data']['openid']??'';
                $data['unionid'] = $res['data']['unionid']??'';
                return $data;
            }else{
                return false;
            }
        }
        return false;

    }

}